<?php

namespace Packages\Sms\Controllers\Client;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Packages\Sms\Services\SmsService;

class SmsController extends Controller
{
    protected SmsService $smsService;

    public function __construct(SmsService $smsService)
    {
        $this->smsService = $smsService;
    }

    /**
     * 发送短信验证码
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function smsCode(Request $request)
    {
        // 定义业务参数验证规则 验证参数
        $params = $this->validateParams($request, [
            'phone' => 'required|regex:/^1[0-9]{10}$/',
            'type' => 'required|string|min:4|max:12',
        ]);

        // 发送短信校验码
        $result = $this->smsService->sendValidSMS($params['phone'], $params['type']);

        return $this->returnRes($result);
    }
}
